package com.atguigu.gmall.product.mapper;

import com.atguigu.gmall.model.product.SkuInfo;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Update;

/***
 * sku信息表dao层mapper映射
 */
@Mapper
public interface SkuInfoMapper extends BaseMapper<SkuInfo> {

    /**
     * 订单生成减库存
     * @param skuId
     * @param skuNum
     * @return
     */
    @Update("UPDATE `sku_info` SET stock = stock - #{skuNum} WHERE stock >= #{skuNum} AND id = #{skuId}")
    int decountStock(Long skuId, Integer skuNum);

    /**
     * 取消订单回滚库存
     * @param skuId
     * @param skuNum
     * @return
     */
    @Update("UPDATE `sku_info` SET stock = stock + #{skuNum} WHERE id = #{skuId}")
    int rollbackStock(Long skuId, Integer skuNum);
}
